package com.lazily.codeblock_;


/**
 * @Author:  GZQ
 * @date:  2025/1/20 22:41
 * @description: 代码块入门
 */

public class CodeBlock01 {
    public static void main(String[] args) {
        Movie m1 = new Movie("《速度与激情7》");
        System.out.println("============================");
        Movie m2 = new Movie("《速度与激情7》", 88);
        System.out.println("============================");
        Movie m3 = new Movie("《速度与激情7》", 88, "罗伯·罗伯森");
    }
}


class Movie {
    private String name;
    private int price;
    private String director;

    // 3个构造器 -> 重载

    // (1) 下面的三个构造器, 都有相同的语句
    // (2) 这样的代码看起来比较冗余
    // (3) 这时我们可以把相同的语句, 放到一个代码块中, 即可
    // (4) 这样当我们不管调用那个构造器, 都会先调用代码块的内容
    // (5) 代码块调用的顺序优先于构造器
    {
        System.out.println("电影屏幕打开啦...");
        System.out.println("广告开始...");
        System.out.println("电影正式开始...");
    }

    public Movie(String name) {
        System.out.println("Movie(String name) 被调用...");
        this.name = name;
    }

    public Movie(String name, int price) {
        System.out.println("Movie(String name, int price) 被调用...");
        this.name = name;
        this.price = price;
    }

    public Movie(String name, int price, String director) {
        System.out.println("Movie(String name, int price, String director) 被调用...");
        this.name = name;
        this.price = price;
        this.director = director;
    }
}